package com.traveling.hztraveling.controller;

import com.traveling.hztraveling.entity.po.HzUser;
import com.traveling.hztraveling.entity.po.Password;
import com.traveling.hztraveling.entity.vo.Result;
import com.traveling.hztraveling.service.ProfileService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@RestController
@RequestMapping("/user")
@Slf4j
@RequiredArgsConstructor
 @Api(tags = "用户信息接口")
public class ProfileController {

    private final ProfileService profileService;

    @GetMapping("/{userId}")
    public Result<HzUser>  getProfile(@PathVariable("userId") Integer userId) {
        return profileService.getProfile(userId);
    }

    @PutMapping ("/{userId}")
     public Result<HzUser> updateProfile(@PathVariable("userId") Integer userId, @RequestBody HzUser hzUser) {
        hzUser.setId( userId);
        return profileService.updateProfile(hzUser);
    }

    @PutMapping ("/{userId}/password")
    public Result<HzUser> updatePassword(@PathVariable("userId") Integer userId, @RequestBody Password password) {
        return profileService.updatePassword(userId,password);
    }

    @PostMapping("/{userId}/avatar")
    public Result  updateAvatar(@PathVariable Integer userId, @RequestParam("avatar") MultipartFile file) {
        return  profileService.updateAvatar(userId,file);
    }


}
